<?php

include_once 'modules/user/models/User.php';
include_once 'modules/content/models/Content.php';
require_once 'modules/list/models/List.php';
require_once 'libs/mail/smtp.php';
class contact_IndexController extends Nine_Controller_Action
{
	public function indexAction()
	{
		/**
		 * Display tempalte
		 */
	    $this->view->headTitle('Contact Us');
	    $this->view->menuId = 'contactus';
	    $this->setLayout('contact');
	    
	    /**
	     * Get post data
	     */
	    $data = $this->_getParam('data', false);
	    $error = array(); 
	    /**
         * Get post data
         */
        $data = $this->_getParam('data', false);
		if (false != $data) {
			
				try {
						/**
				         * Get admin
				         */
				        $objUser = new Models_User();
				        $admin = $objUser->getByUserName('admin');
				        /**
				         * Send message
				         */
				        /**
				         * Send to admin
				         */
				        $string = "Hi Admin, <br/>You have a new contact from your website with the following information:<br/>Name: [NAME]<br/>Email: [EMAIL]<br/>Phone: [PHONE]<br/>Message:[MESSAGE]";
				        $string = str_replace("[NAME]", $data['name'] , $string);
				        $string = str_replace("[EMAIL]", $data['email'] , $string);
				        $string = str_replace("[PHONE]", $data['phone'] , $string);
				        $string = str_replace("[MESSAGE]", $data['message'] , $string);
				        
//				        $admin['email']
				        SendMail( "coder@hangxachtay99.com",$admin['email'],'Liên Hệ', $string,"Content Testing");
				        
				        $this->session->contactMessage = array(
				                                               'success' => true,
				                                               'message' => Nine_Language::translate('We recieved your message.We will contact you soon!')
				                                           );
				        $this->_redirect("/contact-us.html");
					}
				catch (Exception $e) {
					 $this->session->contactMessage = array(
		                                               'success' => false,
		                                               'message' => Nine_Language::translate('Can NOT send this message. Please try again')
		                                           );
				}
				
			
		}
//       }

		/**
		 * Setbanner
		 */
		
        /**
         * Assign to view
         */
	   if ( $this->session->contactMessage != null){
		    $contact = $this->session->contactMessage;
	//	     echo "<pre>";print_r($contact);die;
		    $this->view->contactMessage = $contact;
	        $this->session->contactMessage = null;
	   }
        
        /**
		 * Contact information
		 */
	    
	}
}